#!/usr/bin/python
# -*- coding: utf-8 -*-

import re
# 定义分段正则
regEx = re.compile((r'.*(<VirtualHost \*:443>([\s\S]*?)</VirtualHost>).*'))
regName = re.compile(r'ServerName.*')

# 读取配置文件
with open('vhost.conf', 'r') as f:
    conf_list = f.readlines()

conf_s = "".join(conf_list)
# 正则匹配
result = regEx.findall(conf_s)
for i in range(len(result)):
    vhost = result[i]
    vhost = ''.join(vhost)
    if regName.search(vhost).group():
        ServerName = regName.search(vhost).group()
        ServerName = ServerName[10:].strip()
        print(ServerName)



